﻿///-----------------------------------------------------------------------
/// <copyright file="TabsViewModelBase.cs" company="FactSet Research Systems, Inc.">
///     Copyright © FactSet Research Systems, Inc.  All rights reserved 2012.
/// </copyright>
/// <author>Jonathan K. Barez</author>
///-----------------------------------------------------------------------
namespace HousholdISv2.ViewModel.Core
{
    using System;
    using System.Windows;
    using System.Windows.Controls;
    using MVVMCore.ViewModel;
    using MVVMCore.ViewModel.Details;

    public abstract class TabsViewModelBase : CollectionViewModel<ViewModelBase>
    {
        #region Events

        public event EventHandler BackButtonClicked = delegate { };

        #endregion Events

        #region Properties

        public CommandCollectionViewModel Navigation
        {
            get { return this.GetValue(() => this.Navigation) ?? this.InitializeNavigation(); }
            set { this.SetValue(() => this.Navigation, value); }
        }

        #endregion Properties

        #region Methods

        protected virtual void OnBackButtonClicked(EventArgs e)
        {
            this.BackButtonClicked(this, e);
        }

        protected virtual CommandCollectionViewModel InitializeNavigation()
        {
            var navi =
                new CommandCollectionViewModel
                {
                    Orientation = Orientation.Horizontal,
                    VerticalAlignment = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Right,
                    CommandSpacing = 5,
                    Margin = new Thickness(5),
                };
            navi.Add(
                new CommandViewModel(
                    "Back to Main Menu...",
                    param => this.OnBackButtonClicked(EventArgs.Empty),
                    param => this.CanGoBack())
                {
                    Width = 130
                });
            return this.Navigation = navi;
        }

        protected abstract bool CanGoBack();

        #endregion Methods
    }
}
